﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace _006
{
    internal class Program
    {
        static FileStream fs;
        static StreamWriter sw;
        //委托声明
        public delegate void printString(string s);
        //该方法打印到控制台
        public static void WriteToSCreen(string str)
        {
            Console.WriteLine("The String is:{0}",str);
        }
        //该方法打印到文件
        public static void WriteToFile(string s)
        {
            fs = new FileStream("E:\\VS2022/message.txt", FileMode.Append, FileAccess.Write);
            sw = new StreamWriter(fs);
            sw.WriteLine(s);
            sw.Flush();
            sw.Close();
            fs.Close();
        }
        //该方法把委托作为参数，并使用它调用方法
        public static void sendString(printString ps)
        {
            ps("C#中文网");
        }
        static void Main(string[] args)
        {
            printString ps1 = new printString(WriteToSCreen);
            printString ps2 = new printString(WriteToFile);
            sendString(ps1);
            sendString(ps2);
            Console.ReadKey();
        }
    }
}
